package zju.lzy.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import zju.lzy.dto.User;

import javax.annotation.ManagedBean;
import java.util.List;

/**
 * @author lzy
 */
@Mapper
public interface UserMapper extends GeneralMapper{

    @Insert("insert into user(userId,userName,email,password) value (0,#{userName},#{email},#{password});")
    boolean createUser(@Param("userName") String userName,
                       @Param("email") String email,
                       @Param("password") String password);


    @Select("select * from user where email=#{email} and password=#{pwd}")
    List<User> fetchUserByEmailAndPwd(@Param("email") String email,
                                      @Param("pwd") String pwd);

    @Select("select * from user;")
    List<User> getAllUsers();

    @Select("select * from user where userId=#{id};")
    User getUserById(@Param("id") Integer userId);

    @Select("select * from user where userName=#{name};")
    User getUserByName(@Param("name") String name);
}
